﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

namespace GSManager
{
    public class DichVu
    {
        private string _MaDichVu;
        private string _TenDichVu;
        private decimal _DonGia;
        public string MaDichVu
        {
            get { return _MaDichVu; }
            set { _MaDichVu = value; }
        }
        public string TenDichVu
        {
            get { return _TenDichVu; }
            set { _TenDichVu = value; }
        }
        public decimal DonGia
        {
            get { return _DonGia; }
            set { _DonGia = value; }
        }
        public void ThemDichVu()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Insert into LOAIDICHVU values(?,?,?)";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@MaDichVu", OleDbType.VarChar);
            cmd.Parameters.Add("@TenDichVu", OleDbType.VarWChar);
            cmd.Parameters.Add("@DonGia", OleDbType.Decimal);
            cmd.Parameters[0].Value = MaDichVu;
            cmd.Parameters[1].Value = TenDichVu;
            cmd.Parameters[2].Value = DonGia;
            cmd.ExecuteNonQuery();
            connect.Close();
        }
        public void XoaDichVu(string madv)
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Delete from LOAIDICHVU where MaDichVu='" + madv + "'";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.ExecuteNonQuery();
            connect.Close();
        }
        public void CapNhat()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Update LOAIDICHVU SET DonGia=? where MaDichVu=?";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@DonGia", OleDbType.Decimal);
            cmd.Parameters[0].Value = DonGia;
            cmd.Parameters.Add("@MaDichVu", OleDbType.VarChar);
            cmd.Parameters[1].Value = MaDichVu;
            cmd.ExecuteNonQuery();
            connect.Close();
        }
        public void CapNhatDichVu()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Update LOAIDICHVU set TenDichVu=?,DonGia=? where MaDichVu=?";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@TenDichVu", OleDbType.VarWChar);
            cmd.Parameters.Add("@DonGia", OleDbType.Decimal);
            cmd.Parameters.Add("@MaDichVu", OleDbType.VarChar);
            cmd.Parameters["TenDichVu"].Value = TenDichVu;
            cmd.Parameters["DonGia"].Value = DonGia;
            cmd.Parameters["MaDichVu"].Value = MaDichVu;
            cmd.ExecuteNonQuery();
            connect.Close();
        }
        public DataSet LayDanhSach()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select * from LOAIDICHVU";
            OleDbDataAdapter adapter = new OleDbDataAdapter(sql, connect);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "LOAIDICHVU");
            connect.Close();
            return ds;
        }
        public DichVu LayDichVu(string madichvu)
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select * from LOAIDICHVU where MaDichVu='" + madichvu + "'";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            DichVu dichvu = new DichVu();
            while (r.Read())
            {
                dichvu.MaDichVu = (string)r[0];
                dichvu.TenDichVu = (string)r[1];
                dichvu.DonGia = (decimal)r[2];
            }
            r.Close();
            connect.Close();
            return dichvu;
        }
        public AutoCompleteStringCollection LayDanhSachTenDV()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Select TenDichVu from LOAIDICHVU";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            AutoCompleteStringCollection list = new AutoCompleteStringCollection();
            while (r.Read())
            {
                string kq = (string)r[0];
                list.Add(kq);
            }
            r.Close();
            connect.Close();
            return list;
        }
        public DichVu LayDichVuTheoTen(string tendv)
        {

            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Select * from LOAIDICHVU where TenDichVu=?";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@TenDichVu", OleDbType.VarWChar);
            cmd.Parameters[0].Value = tendv;
            OleDbDataReader r = cmd.ExecuteReader();
            DichVu dichvu = new DichVu();
            while (r.Read())
            {
                dichvu.MaDichVu = (string)r[0];
                dichvu.TenDichVu = (string)r[1];
                dichvu.DonGia = (decimal)r[2];
            }
            r.Close();
            connect.Close();
            return dichvu;
        }
        public bool KiemTraMaDichVu(string madichvu)
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select * from LOAIDICHVU where MaDichVu='" + madichvu + "'";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            bool kq = r.Read();
            r.Close();
            connect.Close();
            return kq;
        }
        public bool KiemTraTenDichVu(string tendichvu)
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select * from LOAIDICHVU where TenDichVu='" + tendichvu + "'";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            bool kq = r.Read();
            r.Close();
            connect.Close();
            return kq;
        }
    }
}
